/**
 * @author jjophin
 */
/* 
 * The function implements the 11 proof validation for validating The Netherlands bank account numbers.
 */

 function validateAccNumber(bankNum){
	//The number should contain only 9 or 10 digits
	if(bankNum.search(/^[0-9]{9,10}$/) == -1)
		return {isValid : false, errorString : "Bank account number must only have 9 or 10 digits."};
	//The number cannot have all digits as zero
	if(bankNum.search(/^0*$/) != -1)
		return {isValid : false, errorString : "Bank account number cannot have all digits as zero"};
 	var numArr = bankNum.split("").reverse();
	var sum = 0;
	//(d10 * 10 + d9 * 9 + ... + d1 * 1) % 11 == 0 //true, the bank number is valid for 10 digits
	//(d9 * 9 + ... + d1 * 1) % 11 == 0 //true, the bank number is valid for 9 digits
	for(var i=1; i<=numArr.length; i++)
		sum += (i * parseInt(numArr[i-1]));
	return {isValid: (sum % 11 == 0)};
 }
